// pages/mall/proList/proList.js
import * as API_Mall_Product from '../../../api/mall/product'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    title:'',
    classifyId:'',
    productList:[],
    isFinshed:false,
    params:{
      secondClassifyId:'',
      searchValue:'',
      pageNum:1,
      pageSize:10,
      orderByColumn:'',//{"userName":"ascending","userId":"descending"}
    },
    sort:["","ascending","descending"],
  },
  loadCartNum(){
    let guide = this.selectComponent("#cart")
    guide.loadCount()
   },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
debugger
let search=options.search;
    this.setData({
      title:search+" 相关的商品",
      'params.searchValue':search
    })
    this.initGlobalData();
    this.loadData()
  },
  loadData(){
    API_Mall_Product.getList(this.data.params).then(res=>{
      let arr = this.data.productList
      arr.push(...res.rows)
      this.setData({
        productList:arr,
        isFinshed:res.lastPage
      })
    })
  },
  initGlobalData:function(){
    let globalData=getApp().globalData;
    let statusBarHeightpx=globalData.statusBarHeightpx;
    let navHeadHeightpx=globalData.navHeadHeightpx;
    let navHeightpx=globalData.navHeightpx;
    this.setData({navHeadHeightpx:navHeadHeightpx,navHeightpx:navHeightpx,statusBarHeightpx:statusBarHeightpx});
  },
  goDetail(e){
    wx.navigateTo({
      url: '../../mall/proDetail/proDetail?id='+e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   this.loadCartNum()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.isFinshed)
      return

    let page = this.data.params.pageNum+1
    this.setData({
      'params.pageNum':page
    })
      this.loadData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})